﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Kmust.Commom
{
    public static class ExtensionMethods
    {
        public static void ExpandAll(this System.Windows.Controls.TreeView treeView)
        {
            ExpandInternal(treeView);
        }
        private static void ExpandInternal(ItemsControl targetItemContainer)
        {
            if (targetItemContainer == null) return;
            if (targetItemContainer.Items == null) return;
            for (int i = 0; i < targetItemContainer.Items.Count; i++)
            {
                TreeViewItem treeItem = targetItemContainer.Items[i] as TreeViewItem;
                if (treeItem == null) continue;
                if (!treeItem.HasItems) continue;
                treeItem.IsExpanded = true;
                ExpandInternal(treeItem);
            }
        }
    }
}
